/*
 * Package il.ac.biu.cs.grossmm.api.flow
 * File ConverterBase.java
 * 
 * This is a part of presence service framework API. 
 * See javadoc for more information.
 *  
 * Copyright (C) 2006 Grossmann Mark
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package il.ac.biu.cs.grossmm.api.flow;

import il.ac.biu.cs.grossmm.api.data.NodeType;
import il.ac.biu.cs.grossmm.api.server.ServiceManager;

/**
 * 
 * A base class to simplify implementation of <tt>Converter</tt>
 * interface.
 * 
 * @see Converter
 */
 public abstract class ConverterBase<Nsrc, Ndst> extends DataProcessorBase implements
	Converter<Nsrc, Ndst> {

	protected double priority;
	private NodeType<Nsrc> srcType;
	private NodeType<Ndst> dstType;


	/**
	 * Constructor
	 * @param name module name
	 * @param srcType source data node type
	 * @param dstType destination data node type
	 * @param priority priority in range (0.0, 1.0]
	 */
	public ConverterBase(String name, NodeType<Nsrc> srcType,
		NodeType<Ndst> dstType, double priority)
	{
		super(name, false);

		this.srcType = srcType;
		this.dstType = dstType;
		this.priority = priority;
	}

	/**
	 * @param name
	 * @param admHint
	 * @param needThread
	 */
	public ConverterBase(String name, Object admHint, NodeType<Nsrc> srcType,
		NodeType<Ndst> dstType, double priority)
	{
		super(name, admHint, false);

		this.srcType = srcType;
		this.dstType = dstType;
		this.priority = priority;
	}
	
	@Override
	public synchronized void start(ServiceManager serviceManager) throws Exception
	{
		super.start(serviceManager);
		
		adm.registerConverter(this);
	}

	public double getPriority()
	{
		return priority;
	}

	public NodeType<Nsrc> getSourceType()
	{
		return srcType;
	}

	public NodeType<Ndst> getDestinationType()
	{
		return dstType;
	}
}
